//
// Created by grainlee on 16/9/8.
//

#include <iostream>
using namespace std;

bool match(char *s, char *p){
    if (0 == (*p)) return 0 == (*s);
    if( *(p+1) != '*'){
        if ((*p == *s) && (*s != 0 || *p == '.'))
            return match(s+1,p+1);
        return false;
    }else{
        while ( *p == *s || (*p == '.' && *s !=0)){
            if(match(s,p+2)){
                return true;
            }
            s++;
        }
        return match(s,p+2);

    }

}

bool isMatch(string s, string p){
    return match(&s[0],&p[0]);
}

int main(){
    string s = "aa";
    string p = "a*";
    cout << isMatch(s,p);
}
